app.controller('agreeOffLease', function($element, ngDialog ,$scope, $state, rest, user,uploadConf,tipService,uiLoad,$localStorage) {
    var data = angular.copy($scope.ngDialogData, {});
    $scope.params = {
      initiatorOpenId: user.get('openId')
    };
    $scope.leaseTime = data.exitDate;
    console.log($scope.leaseTime);

    $scope.params.contractId = data.contractId;
    $scope.params.exitDate = data.exitDate;
    $scope.now = function(){
      var d = new Date();
      var year = d.getFullYear();
      var month = d.getMonth() + 1;
      var dt = d.getDate();
      if (month<10) {
          $scope.today = year + "-" + "0"+month + "-" + dt + " 00:00:00";
        }else{
          $scope.today = year + "-" + month + "-" + dt + " 00:00:00";
        }
    }
    //点击同意按钮
    $scope.agreeLeave = function() {
      console.log(data);
      $scope.now();
      if ($scope.params.exitDate == $scope.today) {
        $scope.params.statusName = "OrderOutOver";
      }else{
        $scope.params.statusName = "OrderPreOutApply";
      }
      
      $scope.closeThisDialog({clickOk: true});
      rest.post({
          methodId: '1050',
          data: $scope.params,
          success: function(res) {
              if (res.code == 0) {
                  tipService.show("body", {
                      message: "已同意退租申请,跳转中......"
                  }, 3);
              } else {
                  tipService.show("body", {
                      message: res.res.msg,
                      notice: "danger"
                  }, 3);
              }
          },
          error: function() {
              btn.removeClass('disabled');
          }
      })
    }

    //点击拒绝按钮
    $scope.disagreeLeave = function() {
      console.log(data);
      $scope.params.statusName = "OrderRepayment";
      $scope.closeThisDialog({clickOk: true});
      rest.post({
          methodId: '1050',
          data: $scope.params,
          success: function(res) {
              if (res.code == 0) {
                  tipService.show("body", {
                      message: "已拒绝退租申请,跳转中......"
                  }, 3);
              } else {
                  tipService.show("body", {
                      message: res.res.msg,
                      notice: "danger"
                  }, 3);
              }
          },
          error: function() {
              btn.removeClass('disabled');
          }
      })
    }
});
